package com.stockz.equity.charting.display.screen;

import java.util.ArrayList;
import java.util.List;

import com.stockz.equity.model.Bar;
import com.stockz.equity.scanner.screen.Screen;

public class DisplayableScreenUtil {

	public static <T> int[] getScreenMatches(List<Bar> barList, Screen<T> screen){
		if(barList == null 
				|| screen == null
				|| barList.size() < screen.getMandatorySpan()){
			return new int[0];
		}
		
		ArrayList<Integer> matchList = new ArrayList<Integer>();
		for(int i = 0; i < barList.size() - screen.getMandatorySpan(); i++){
			if(screen.isMatch(barList.subList(i, barList.size()))){
				matchList.add(i);
			}
		}
		
		int[] out = new int[matchList.size()];
		for(int i = 0; i < matchList.size(); i++){
			out[i] = matchList.get(i);
		}
		
		return out;
	}
	
}
